package gatperdut.chato.core.interpreter.actions;

import gatperdut.chato.constants.CSConstantsCommandResult.CommandExecutionResult;
import gatperdut.chato.constants.CSConstantsString;
import gatperdut.chato.core.characters.BaseController;
import gatperdut.chato.core.interpreter.actions.generic.LookAction;
import gatperdut.chato.core.interpreter.grammar.comminfo.LookInfo;
import gatperdut.chato.core.item.ItemController;

public class LookAtAction extends LookAction {

    public LookAtAction( LookInfo info, BaseController entityController ) {
        super( info, entityController );
    }

    @Override
    public CommandExecutionResult perform() {
        checkForRunningCraft();

        StringBuilder message = new StringBuilder( "" );

        // --lookin at object?
        ItemController ic = findInRoomOrInventory( getInfo().getWhat(), getInfo().isGround() );
        if ( ic != null ) {
            message.append( ic.getShortDesc( true ) + ":" + CSConstantsString.NEWLINE + ic.getFullDesc() );
            getEntityController().tx( message.toString() );
            return CommandExecutionResult.OK;
        }

        // --looking at character?
        BaseController bc = getEntityController().getRoomController().getCharactersController().getEntityController( getInfo().getWhat() );
        if ( bc != null ) {
            message.append( bc.getCharacter().getShortDesc() + ":" + CSConstantsString.NEWLINE + bc.getCharacter().getFullDesc() );
            message.append( CSConstantsString.NEWLINE + "Carrying:" + CSConstantsString.NEWLINE );
            message.append( bc.getInventoryController().listContentsShortDescription( false ) );
            getEntityController().tx( message.toString() );
            return CommandExecutionResult.OK;
        }
        else {
            getEntityController().tx( "You cannot find that here." );
            return CommandExecutionResult.OK;
        }
    }

}
